package oop5;

/**
 * @author oldliu
 * @since 1.0
 */
public class Ex2 {
    //偶数都放左边，奇数放右边
    public static void main(String[] args) {
        int[] a = {1, 3, 23, 5, 16, 82, 14, 18};
        //插入排序的思路
        int start = 0, end = a.length - 1;
        while (start < end) {
            if (a[start] % 2 != 0) {
                if (a[end] % 2 == 0) {
                    int temp = a[start];
                    a[start] = a[end];
                    a[end] = temp;
                    start++;
                    end--;
                } else {
                    end--;
                }
            } else {
                start++;
            }
        }

        //冒泡
//        for (int i = 0; i < a.length - 1; i++) {
//            for (int j = 0; j < a.length - 1 - i; j++) {
//                if (a[j] % 2 != 0) {
//                    int temp = a[j + 1];
//                    a[j + 1] = a[j];
//                    a[j] = temp;
//                }
//            }
//        }
        for (int i = 0; i < a.length; i++) {
            System.out.print(a[i] + " ");
        }

    }
}
